package cz.najman.emdroid.connection;

import java.io.IOException;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;

import cz.najman.emdroid.listener.OnResponseDataParsedListener;

/**
 * @author  Lukáš Najman
 */
public abstract class AbstractResponseHandler implements ResponseHandler{
	
	/**
	 * Local variable that holds the response code of the request
	 */
	protected Integer mResponseCode = null;
	/**
	 * Id that identify the request
	 */
	protected Long mRequestId;	
	/**
	 * Listener that is fired back, when the new data are retrieved, or the error occurred
	 */
	protected OnResponseDataParsedListener mListener;	
	
	@Override
	public abstract Integer handleResponse(HttpResponse response) throws ClientProtocolException, IOException;

	@Override
	public boolean hasResponseCode() {
		if(mResponseCode != null)
			return true;
		return false;
	}

	@Override
	public int getResponseCode() {		
		return mResponseCode;		
	}

	@Override
	public void registerListener(OnResponseDataParsedListener listener) {
		mListener = listener;
		
	}
	
	
	public void setResponseCode(int responseCode){
		mResponseCode = responseCode;
	}
	
	@Override
	public long getRequestId() {
		return mRequestId;
	}

	@Override
	public void setRequestId(Long requestId) {
		mRequestId = requestId;
		
	}

}
